package com.ak.server.platform.controller;

import com.ak.common.controller.BaseController;
import com.ak.common.entity.AKResponse;
import com.ak.server.platform.entity.Area;
import com.ak.server.platform.service.IAreaService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Vean
 */
@Api(tags = "区域管理表")
@RestController
@RequestMapping("/area")
@RequiredArgsConstructor
public class AreaController extends BaseController {

    private final IAreaService areaService;

    /**
     * 级联查询缓存中的地区
     *
     * @param parentId 父ID
     * @return 查询结果
     */
    @ApiOperation(value = "级联查询地区", notes = "级联查询地区")
    @GetMapping
    public AKResponse linkageQuery(@RequestParam(defaultValue = "0", required = false) Long parentId) {
        LambdaQueryWrapper<Area> query = new LambdaQueryWrapper<Area>().eq(Area::getParentId, parentId);
        return new AKResponse().data((areaService.list(query)));
    }

}
